'''
Author: Leo.wang wanglizhigs@163.com
Date: 2025-09-05 20:36:09
LastEditors: Leo.wang wanglizhigs@163.com
LastEditTime: 2025-09-05 21:15:51
FilePath: /medical-companion-server-python/app/patient/serializers.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
from rest_framework import serializers
from .models import McPatient, McUser, McGender, McIdentity
from app.user.serializers import McForeignUserSerializer
from app.gender.serializers import McGenderSerializer
from app.identity.serializers import McIdentitySerializer


class McPatientSerializer(serializers.ModelSerializer):
    user = McForeignUserSerializer(read_only=True)
    gender = McGenderSerializer(read_only=True)
    identity = McIdentitySerializer(read_only=True)

    user_id = serializers.PrimaryKeyRelatedField(
        queryset=McUser.objects.all(), source="user", write_only=True
    )
    gender_id = serializers.PrimaryKeyRelatedField(
        queryset=McGender.objects.all(), source="gender", write_only=True
    )
    identity_id = serializers.PrimaryKeyRelatedField(
        queryset=McIdentity.objects.all(), source="identity", write_only=True
    )
    class Meta:
        model = McPatient
        fields = '__all__'

class McForeignPatientSerializer(serializers.ModelSerializer):
    class Meta:
        model = McPatient
        fields = ['id','identity_number','gender','age','name']
